<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>原料仓库管理系统</title>
</head>
<?php
session_start();
if ($_SESSION['username']!=null){
	
}else{
	 echo"<script type='text/javascript'>location='CKGL-index.php';
			</script>";
}
?>
<link rel="stylesheet" type="text/css" href="css/ckgl_cksj.css" />
<?php 
require('lianjie.php');
?>
<body>
<a href="CKGL_no1.php">返回首页</a>
<form action="CKGL_cksj.php" method="POST" name="f1">
<table align="center" width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000" bgcolor="#c3c3c3">
<tr>
<td align="center"><input type="date" name="d1" value="<?php echo date('Y-m-d',strtotime('-1 month')); ?>" />~<input type="date" name="d2" value="<?php echo date('Y-m-d'); ?>" /></td>
<td>厂商:<input type="text" name="LY" value="" /></td>
<td>库区:<input type="text" name="KQ" value="" /></td>
</tr>
<tr>
<td align="center">名称:<input type="text" name="name" value="" /></td>
<td align="center">批号:<input type="text" name="PH" value="" /></td>
<td align="center">手册号:<input type="text" name="id" value="" /></td>
<td align="center"><select name="rck_xz">
    <option value="hz" selected>结存</option>
    <option value="ckb">出库</option>
    <option value="rkb">入库</option>
    <option value="zkb">转库</option>
    </select></td>
<td><input type="submit" name="sub" value="确定" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="rst" value="清除" /></td>
</tr>
</table>
</form>
<div class="box_CZJL">
<table align="center" width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000" bgcolor="#c3c3c3" style="font-size:9px">

<?php

if(isset($_POST['rck_xz'])){
	$xz=$_POST['rck_xz'];}
else{$xz="";}


if(mysqli_select_db($connID,$dbName)){
	$pagesize=8;
			if(empty($_GET['page']))
			{
				$page=1;
				$startrow=0;
			}
			else
			{
				$page=(int)$_GET['page'];
				$startrow=($page-1)*$pagesize;
			}
		$pagesql="select * from rkb;";
		$pageresult=mysqli_query($connID,$pagesql);
		$records=mysqli_num_rows($pageresult);
		$pages=ceil($records/$pagesize);
}


if($xz=="rkb"){
	$d1=$_POST['d1'];
	$d2=$_POST['d2'];
	if(isset($_POST['name'])){
		$n="'%".$_POST['name']."%'";
	}
	else{$n="'%%'";}
	if(isset($_POST['PH'])){
		$p="'%".$_POST['PH']."%'";
	}
	else{$p="'%%'";}
	if(isset($_POST['id'])){
		$i="'%".$_POST['id']."%'";
	}
	else{$i="'%%'";}
	if(isset($_POST['LY'])){
		$l="'%".$_POST['LY']."%'";
	}
	else{$l="'%%'";}
	if(isset($_POST['KQ'])){
		$k="'%".$_POST['KQ']."%'";
	}
	else{$k="'%%'";}
	?>
    <thead>
    <tr>
    <th>时间</th>
    <th>名称</th>
    <th>批号</th>
    <th>手册号</th>
    <th>合同号</th>
    <th>单据号</th>
    <th>实物量</th>
    <th>钴量</th>
    <th>镍量</th>
    <th>锰量</th>
    <th>铜量</th>
    <th>锂量</th>
    <th>包数</th>
    <th>来源</th>
    <th>库区</th>
    <th>储位</th>
    <th>原料类别</th>
    <th>表类别</th>
    <th>两大类别</th>
    <th>类别1</th>
    <th>类别2</th>
    <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php
	if(mysqli_select_db($connID,$dbName)){
		$sql="select * from rkb where (name like".$n." and PH like".$p." and id like".$i." and LY like".$l." and KQ like".$k.") and (dh_date>='".$d1."' and dh_date<='".$d2."') order by dh_date desc;";
		$sum=20;
		$result=mysqli_query($connID,$sql);
		//echo $sql;
		$arr=array(0=>$sum,1=>'25',2=>'入库数据',3=>'时间',4=>'名称',5=>'批号',6=>'手册号',7=>'合同号',8=>'单据号',9=>'实物量',10=>'钴',11=>'镍',12=>'锰',13=>'铜',14=>'锂',15=>'包数',16=>'来源',17=>'库区',18=>'储位',19=>'原料类别',20=>'表类别',21=>'两大类别',22=>'类别1',23=>"类别2",24=>"".$sql."");
		$url1='Excel_dy.php?'.http_build_query($arr);
		while($myrow=mysqli_fetch_array($result)){
		?>
		<tr>
		<td align="center"><span class="STYLE2"><?php echo $myrow[0];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[1];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[2];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[3];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[4];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[5];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[6];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[7];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[8];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[9];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[10];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[11];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[12];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[13];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[14];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[15];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[16];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[17];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[18];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[19];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[20];?></span></td>
		<?php $arr=array(0=>$myrow[1],1=>$myrow[2],2=>$myrow[3],3=>'rkb');
		$url='CKGL_cksj_updata.php?'.http_build_query($arr);?>
		<td align="center"><a href="<?php echo $url;?>">修改</a></td>
		</tr>
		</tr>
		<?php
		}
	}
}
else if($xz=="ckb"){
	$d1=$_POST['d1'];
	$d2=$_POST['d2'];
	if(isset($_POST['name'])){
		$n="'%".$_POST['name']."%'";
	}
	else{$n="'%%'";}
	if(isset($_POST['PH'])){
		$p="'%".$_POST['PH']."%'";
	}
	else{$p="'%%'";}
	if(isset($_POST['id'])){
		$i="'%".$_POST['id']."%'";
	}
	else{$i="'%%'";}
	if(isset($_POST['LY'])){
		$l="'%".$_POST['LY']."%'";
	}
	else{$l="'%%'";}
	if(isset($_POST['KQ'])){
		$k="'%".$_POST['KQ']."%'";
	}
	else{$k="'%%'";}
	?>
    </tbody>
    <thead>
    <tr>
    <th>时间</th>
    <th>名称</th>
    <th>批号</th>
    <th>手册号</th>
    <th>合同号</th>
    <th>单据号</th>
    <th>实物量</th>
    <th>钴量</th>
    <th>镍量</th>
    <th>锰量</th>
    <th>铜量</th>
    <th>锂量</th>
    <th>包数</th>
    <th>去向</th>
    <th>库区</th>
    <th>储位</th>
    <th>原料类别</th>
    <th>表类别</th>
    <th>两大类别</th>
    <th>类别1</th>
    <th>类别2</th>
    <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php
	if(mysqli_select_db($connID,$dbName)){
		$sql="select * from ckb where (name like".$n." and PH like".$p." and id like".$i." and QX like".$l." and KQ like".$k.") and (dh_date>='".$d1."' and dh_date<='".$d2."') order by dh_date desc;";
		$result=mysqli_query($connID,$sql);
		$sum=20;
		//echo $sql;
		$arr=array(0=>$sum,1=>'25',2=>'出库数据',3=>'时间',4=>'名称',5=>'批号',6=>'手册号',7=>'合同号',8=>'单据号',9=>'实物量',10=>'钴',11=>'镍',12=>'锰',13=>'铜',14=>'锂',15=>'包数',16=>'去向',17=>'库区',18=>'储位',19=>'原料类别',20=>'表类别',21=>'两大类别',22=>'类别1',23=>"类别2",24=>"".$sql."");
		$url1='Excel_dy.php?'.http_build_query($arr);
		while($myrow=mysqli_fetch_array($result)){
		?>
		<tr>
		<td align="center"><span class="STYLE2"><?php echo $myrow[0];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[1];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[2];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[3];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[4];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[5];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[6];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[7];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[8];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[9];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[10];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[11];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[12];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[13];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[14];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[15];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[16];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[17];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[18];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[19];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[20];?></span></td>
		<?php $arr=array(0=>$myrow[1],1=>$myrow[2],2=>$myrow[3],3=>'ckb');
		$url='CKGL_cksj_updata.php?'.http_build_query($arr);?>
		<td align="center"><a href="<?php echo $url;?>">修改</a></td>
		</tr>
		</tr>
		<?php
		}
	}
}
else if($xz=="zkb"){
	$d1=$_POST['d1'];
	$d2=$_POST['d2'];
	if(isset($_POST['name'])){
		$n="'%".$_POST['name']."%'";
	}
	else{$n="'%%'";}
	if(isset($_POST['PH'])){
		$p="'%".$_POST['PH']."%'";
	}
	else{$p="'%%'";}
	if(isset($_POST['id'])){
		$i="'%".$_POST['id']."%'";
	}
	else{$i="'%%'";}
	if(isset($_POST['LY'])){
		$l="'%".$_POST['LY']."%'";
	}
	else{$l="'%%'";}
	if(isset($_POST['KQ'])){
		$k="'%".$_POST['KQ']."%'";
	}
	else{$k="'%%'";}
	?>
    </tbody>
    <thead>
    <tr>
    <th>时间</th>
    <th>名称</th>
    <th>批号</th>
    <th>手册号</th>
    <th>合同号</th>
    <th>单据号</th>
    <th>实物量</th>
    <th>钴量</th>
    <th>镍量</th>
    <th>锰量</th>
    <th>铜量</th>
    <th>锂量</th>
    <th>包数</th>
    <th>原来库区</th>
    <th>库区</th>
    <th>储位</th>
    <th>原料类别</th>
    <th>表类别</th>
    <th>两大类别</th>
    <th>类别1</th>
    <th>类别2</th>
    </tr>
    </thead>
    <tbody>
    <?php
	if(mysqli_select_db($connID,$dbName)){
		$sql="select * from zkb where (name like".$n." and PH like".$p." and id like".$i." and KQ like".$k.") and (dh_date>='".$d1."' and dh_date<='".$d2."') order by dh_date desc;";
		$result=mysqli_query($connID,$sql);
		$sum=20;
		//echo $sql;
		$arr=array(0=>$sum,1=>'25',2=>'出库数据',3=>'时间',4=>'名称',5=>'批号',6=>'手册号',7=>'合同号',8=>'单据号',9=>'实物量',10=>'钴',11=>'镍',12=>'锰',13=>'铜',14=>'锂',15=>'包数',16=>'原来库区',17=>'库区',18=>'储位',19=>'原料类别',20=>'表类别',21=>'两大类别',22=>'类别1',23=>"类别2",24=>"".$sql."");
		$url1='Excel_dy.php?'.http_build_query($arr);
		while($myrow=mysqli_fetch_array($result)){
		?>
		<tr>
		<td align="center"><span class="STYLE2"><?php echo $myrow[0];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[1];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[2];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[3];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[4];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[5];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[6];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[7];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[8];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[9];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[10];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[11];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[12];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[13];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[14];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[15];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[16];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[17];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[18];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[19];?></span></td>
        <td align="center"><span class="STYLE2"><?php echo $myrow[20];?></span></td>
		</tr>
		<?php
		}
	}
}
else if($xz=="hz"){
	$d1=$_POST['d1'];
	$d2=$_POST['d2'];
	if(isset($_POST['name'])){
		$n="'%".$_POST['name']."%'";
	}
	else{$n="'%%'";}
	if(isset($_POST['PH'])){
		$p="'%".$_POST['PH']."%'";
	}
	else{$p="'%%'";}
	if(isset($_POST['id'])){
		$i="'%".$_POST['id']."%'";
	}
	else{$i="'%%'";}
	if(isset($_POST['LY'])){
		$l="'%".$_POST['LY']."%'";
	}
	else{$l="'%%'";}
	if(isset($_POST['KQ'])){
		$k="'%".$_POST['KQ']."%'";
	}
	else{$k="'%%'";}
?>
</tbody>
<thead>
<tr>
<th>时间</th>
<th>名称</th>
<th>批号</th>
<th>手册号</th>
<th>实物量</th>
<th>包数</th>
<th>来源</th>
<th>去向</th>
<th>库区</th>
<th>储位</th>
<th>原料类别</th>
<th>表类别</th>
<th>两大类别</th>
<th>类别1</th>
<th>类别2</th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_select_db($connID,$dbName)){
		$sql="select r.dh_date,r.name,r.PH,r.id,(r.s-ifnull(c.s,0)),(r.b-ifnull(c.b,0)),r.LY,c.QX,r.KQ,r.CW,r.YLLB,r.BLB,r.LBLB,r.LB1,r.LB2 from (select dh_date,name,PH,id,sum(SW) as s,sum(BS) as b,LY,KQ,CW,YLLB,BLB,LBLB,LB1,LB2 from rkb group by name,PH,id) as r left join (select name,PH,id,sum(SW) as s,sum(BS) as b,QX from ckb group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where (r.name like".$n." and r.PH like".$p." and r.id like".$i." and r.KQ like".$k." and r.LY like ".$l.") and (r.dh_date>='".$d1."' and r.dh_date<='".$d2."') order by dh_date desc;";
		$result=mysqli_query($connID,$sql);
		//echo $sql;
		$sum=14;
		$arr=array(0=>$sum,1=>'19',2=>'结存数据',3=>'时间',4=>'名称',5=>'批号',6=>'手册号',7=>'实物量',8=>'包数',9=>'来源',10=>'去向',11=>'库区',12=>'储位',13=>'原料类别',14=>'表类别',15=>'两大类别',16=>'类别1',17=>"类别2",18=>"".$sql."");
		$url1='Excel_dy.php?'.http_build_query($arr);
		while($myrow=mysqli_fetch_array($result)){
		?>
		<tr>
		<td align="center"><span class="STYLE2"><?php echo $myrow[0];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[1];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[2];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[3];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[4];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[5];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[6];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[7];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[8];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[9];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[10];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[11];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[12];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[13];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[14];?></span></td>
        </tr>
		<?php
		}
	}
}
else{
	if(isset($_POST['name'])){
		$n="'%".$_POST['name']."%'";
	}
	else{$n="'%%'";}
	if(isset($_POST['PH'])){
		$p="'%".$_POST['PH']."%'";
	}
	else{$p="'%%'";}
	if(isset($_POST['id'])){
		$i="'%".$_POST['id']."%'";
	}
	else{$i="'%%'";}
	if(isset($_POST['LY'])){
		$l="'%".$_POST['LY']."%'";
	}
	else{$l="'%%'";}
	if(isset($_POST['KQ'])){
		$k="'%".$_POST['KQ']."%'";
	}
	else{$k="'%%'";}
?>
</tbody>
<thead>
<tr>
<th>时间</th>
<th>名称</th>
<th>批号</th>
<th>手册号</th>
<th>实物量</th>
<th>包数</th>
<th>来源</th>
<th>去向</th>
<th>库区</th>
<th>储位</th>
<th>原料类别</th>
<th>表类别</th>
<th>两大类别</th>
<th>类别1</th>
<th>类别2</th>
</tr>
</thead>

<?php
if(mysqli_select_db($connID,$dbName)){
		$sql="select r.dh_date,r.name,r.PH,r.id,(r.s-ifnull(c.s,0)),(r.b-ifnull(c.b,0)),r.LY,c.QX,r.KQ,r.CW,r.YLLB,r.BLB,r.LBLB,r.LB1,r.LB2 from (select dh_date,name,PH,id,sum(SW) as s,sum(BS) as b,LY,KQ,CW,YLLB,BLB,LBLB,LB1,LB2 from rkb group by name,PH,id) as r left join (select name,PH,id,sum(SW) as s,sum(BS) as b,QX from ckb group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where (r.name like".$n." and r.PH like".$p." and r.id like".$i." and r.KQ like".$k." and r.LY like ".$l.") order by dh_date desc limit ".$startrow.",".$pagesize.";";
		$result=mysqli_query($connID,$sql);
		//echo $sql;
		$sum=14;
		$arr=array(0=>$sum,1=>'19',2=>'结存数据',3=>'时间',4=>'名称',5=>'批号',6=>'手册号',7=>'实物量',8=>'包数',9=>'来源',10=>'去向',11=>'库区',12=>'储位',13=>'原料类别',14=>'表类别',15=>'两大类别',16=>'类别1',17=>"类别2",18=>"".$sql."");
		$url1='Excel_dy.php?'.http_build_query($arr);
		while($myrow=mysqli_fetch_array($result)){
		?>
		<tr>
		<td align="center"><span class="STYLE2"><?php echo $myrow[0];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[1];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[2];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[3];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[4]?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[5];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[6];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[7];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[8];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[9];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[10];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[11];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[12];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[13];?></span></td>
		<td align="center"><span class="STYLE2"><?php echo $myrow[14];?></span></td>
        </tr>
		<?php
		}
	}
?>

<tr>
	<?php if($page-1>0){ ?>
	<td align="center"><a href="<?php echo $_SERVER['PHP_SELF'] ?>?page=<?php echo $page-1 ?>">上一页</a></td>
	<?php } ?>
	<td align="center"><?php echo "第".$page."页/共".$pages."页"; ?></td>
	<?php if($page+1<=$pages) { ?>
	<td align="center"><a href="<?php echo $_SERVER['PHP_SELF'] ?>?page=<?php echo $page+1 ?>">下一页</a></td>
	<?php } ?>
</tr>
<?PHP
}
?>
</table>
</div>
<a href="<?php echo $url1;?>"><div class="tz">导出</div></a>

</body>
</html>